package com.xbongbong.pro.statistic.service.impl;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.errorcodes.StatisticsServicesErrorCodeEnum;
import com.xbongbong.pro.service.toolbox.statistic.help.ChartDtoHelp;
import com.xbongbong.pro.statistic.enums.PanoramaEnum;
import com.xbongbong.pro.statistic.result.pojo.PanoramaPojo;
import com.xbongbong.pro.statistic.result.pojo.dto.PanoramaDTO;
import com.xbongbong.pro.statistic.result.pojo.vo.PanoramaDataVO;
import com.xbongbong.pro.statistic.result.pojo.vo.PanoramaVO;
import com.xbongbong.pro.statistic.service.ChartPanoramaService;
import com.xbongbong.pro.statistic.service.result.ChartResult;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 全景图实现类
 * @author zcp
 * @version v1.0
 * @date 2019/5/30 15:13
 * @since v1.0
 */
@Service("chartPanoramaService")
public class ChartPanoramaServiceImpl implements ChartPanoramaService {
    @Resource
    private ChartResult chartResult;
    @Resource
    private ChartDtoHelp chartDtoHelp;

    @Override
    public PanoramaVO customer(PanoramaDTO panoramaDto) throws XbbException {
        List<String> codeIn = panoramaDto.getCodeIn();
        List<PanoramaEnum> list = PanoramaEnum.getByCodeIn(codeIn);
        if (list.size() == 0) {
            throw new XbbException(StatisticsServicesErrorCodeEnum.API_ERROR_224022, StatisticsServicesErrorCodeEnum.API_ERROR_224022.getMsg(), I18nMessageUtil.getMessage(I18nStringConstant.PANORAMIC_INDICATOR_GETS_ABNORMAL));
        }
        UserEntity userEntity = BeanUtil.copyProperties(panoramaDto.getLoginUser(), UserEntity.class, false);
        PanoramaPojo panoramaPojo = chartDtoHelp.getPanoramaPojo(userEntity, panoramaDto);
        List<PanoramaDataVO> panoramaDataVoList = new ArrayList<>();
        for (PanoramaEnum panoramaEnum: list){
            //只需要设置code和value即可
            PanoramaDataVO panoramaDataVo = new PanoramaDataVO();
            panoramaDataVo.setCode(panoramaEnum.getCode());
            String value = (String) chartResult.getResult4Panorama(panoramaEnum.getXbbRefTypeEnum(), panoramaPojo, panoramaEnum);
            panoramaDataVo.setValue(value);
            panoramaDataVoList.add(panoramaDataVo);
        }

        PanoramaVO panoramaVo = new PanoramaVO();
        panoramaVo.setData(panoramaDataVoList);
        return panoramaVo;
    }
}
